import { defineStore } from 'pinia'
import { ref, onMounted } from 'vue'
import { useMemberCardStore } from './memberCard'
import { useClassScheduleStore } from './classSchedule'

export const useClassRecordStore = defineStore('classRecord',() => {
    const memberCardStore = useMemberCardStore()
    const classScheduleStore = useClassScheduleStore()
    
    // 模拟上课记录数据
    const classRecords = ref([
        {
            memberId: 1,
            memberCardName: '',
            classScheduleId: 1,
            courseName: '',
            classTime: '',
            teacherName: '',
            memberCardId: 1,
            peopleCount: 2,
            consumeTimes: 3,
            teacherAssessment: '',
            confirmStatus: "已确认"
        }
    ])

    const setInfoToRecords = () => {
        classRecords.value.forEach(record => {
            let memberCard = memberCardStore.getMemberCardById(record.memberCardId)
            let classShedule = classScheduleStore.getClassScheduleById(record.classScheduleId)
            record.classTime = classShedule.classDate + " " + classShedule.classTime
            record.teacherName = classShedule.teacherName
            record.memberCardName = memberCard.memberCardName
            record.courseName = classShedule.courseName
        })
    }

    const getClassRecordsByMemberId = (memberId) => {
        return classRecords.value.filter(record => record.memberId === memberId)
    };
    const getClassRecordsByTeacherName = (teacherName) => {
        return classRecords.value.filter(record => record.teacherName === teacherName)
    };

    onMounted(() => {
        setInfoToRecords()
    })

    return{
        classRecords,
        getClassRecordsByMemberId,
        getClassRecordsByTeacherName
    }
})
